package org.camunda.bpm.getstarted.loanapproval.mapper;

import org.apache.ibatis.annotations.*;
import org.camunda.bpm.getstarted.loanapproval.pojo.entity.TicketDO;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface TicketMapper {

    @Select("select * from tb_ticket where create_time > DATE_SUB(curdate(),INTERVAL 0 DAY)")
    List<TicketDO> selectAll();

    @Select("select COALESCE(MAX(ticket_no),0)+1 from tb_ticket where create_time > DATE_SUB(curdate(),INTERVAL 0 DAY)")
    Integer selectGenerateNo();

    @Insert("insert into tb_ticket(ticket_no,ticket_display_no,create_time,update_time) values(#{ticketNo},#{ticketDisplayNo},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys=true, keyProperty="id")
    Integer insert(TicketDO ticketDO);

    @Select("SELECT t.*,tt.id ticketTaskId FROM tb_ticket t,tb_ticket_task tt,tb_workstation_task wt where t.id = tt.ticket_id and prty_code=#{prtyCode} and wt.ticketTaskId = tt.id and status=#{status} and t.create_time > DATE_SUB(curdate(),INTERVAL 0 DAY) and wt.workstationId = #{workstationId}")
    List<Map> selectWaiting(@Param("prtyCode") String prtyCode,@Param("status") Integer status,@Param("workstationId") Long workstationId);


    @Update("update tb_ticket_task set status=#{status} where id=#{id}")
    void updateStatus(@Param("id") Integer id,@Param("status")  Integer status);

    @Select("select * from tb_ticket where id=#{id}")
    TicketDO selectById(@Param("id") Integer id);
}
